<div class="ui basic segment">
  <h1 class="ui dividing header">
    <%= link("News", to: Routes.admin_news_item_path(@conn, :index)) %>
    &raquo;
    <%= link("Sponsorships", to: Routes.admin_news_sponsorship_path(@conn, :schedule)) %>
    &raquo;
    <%= link(@sponsorship.sponsor.name, to: Routes.admin_sponsor_path(@conn, :edit, @sponsorship.sponsor)) %>

    <div class="ui basic right floated buttons">
      <button class="ui basic icon clipboard button" title="Copy Schedule Text" data-clipboard-text="<%= schedule_text(@sponsorship) %>"><i class="calendar icon"></i></button>
      <%= link("Edit Sponsorship", to: Routes.admin_news_sponsorship_path(@conn, :edit, @sponsorship), class: "ui button") %>
      <%= link("Edit Sponsor", to: Routes.admin_sponsor_path(@conn, :edit, @sponsorship.sponsor), class: "ui button") %>
    </div>

    <div class="sub header"><%= SharedHelpers.pluralize(@sponsorship.ads, "ad", "ads") %> for <%= SharedHelpers.pluralize(@sponsorship.weeks, "week", "weeks") %></div>
  </h1>
</div>

<div class="ui basic segment">
  <h2 class="ui header"><%= @sponsorship.name || "Unnamed" %> Campaign</h2>

  <table class="ui celled unstackable table">
    <thead>
      <tr>
        <th>Weeks</th>
        <th>Ads</th>
        <th>Weeks</th>
        <th><i class="mouse pointer icon"></i> / <i class="eye icon"></i></th>
        <th>CTR</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td><%= length(@sponsorship.weeks) %></td>
        <td><%= length(@sponsorship.ads) %></td>
        <td>
        <%= for week <- @sponsorship.weeks do %>
          <div class="ui label"><%= TimeView.terse_date(week) %></div>
        <% end %>
        </td>
        <td><%= @sponsorship.click_count %> / <%= @sponsorship.impression_count %></td>
        <td><%= SharedHelpers.ctr(@sponsorship) %>%</td>
      </tr>
    </tbody>
  </table>
</div>

<%= for {label, ads} <- [{"Active", active_ads(@sponsorship)}, {"Inactive", inactive_ads(@sponsorship)}] do %>
<div class="ui basic segment">
  <h2 class="ui header"><%= label %> Ads</h2>

  <table class="ui celled striped table">
    <thead>
      <tr>
        <th>Headline</th>
        <th>Link</th>
        <th>Active</th>
        <th><i class="mouse pointer icon"></i> / <i class="eye icon"></i></th>
        <th>CTR</th>
        <th>Create Time</th>
        <th></th>
      </tr>
    </thead>

    <tbody>
    <%= for ad <- ads do %>
      <tr>
        <td><%= ad.headline %></td>
        <td><%= link(SharedHelpers.domain_name(ad.url), to: ad.url) %></td>
        <td><%= ad.active %></td>
        <td><%= ad.click_count %> / <%= ad.impression_count %></td>
        <td><%= SharedHelpers.ctr(ad) %>%</td>
        <td><%= AdminHelpers.ts(ad.inserted_at) %></td>
        <td class="center aligned">
          <div class="ui small basic buttons">
            <%= AdminHelpers.icon_link("eye", to: Routes.news_sponsored_path(@conn, :show, NewsAd.slug(ad))) %>
          </div>
        </td>
      </tr>
    <% end %>
    </tbody>
  </table>
</div>
<% end %>
